<?php


class MappingService {	
	
	function getMapping($mapping){
		$result = null;
		$xml_parser = xml_parser_create();
		
		
		if(!($fp = fopen($mapping, 'r'))){
			die('Could not find Mapping configuration (' . $mapping . ')');				
		}
		
		$content = fread($fp, filesize($mapping));
		fclose($fp);
		
		xml_parse_into_struct($xml_parser, $content, $result);
		xml_parser_free($xml_parser);
				
		return $result;		
	}	
	
	function findElement($type, $name, $mapping, $action = null){	
		if(!isset($action)){
			foreach($mapping as $key=>$value){		
				if($key == 'tag' && $value == $type && array_key_exists('attributes', $mapping)) {
					if(array_key_exists('NAME', $mapping['attributes']) && $mapping['attributes']['NAME'] == $name){
						$action = $mapping; 
						break;
					}			
				} elseif(is_array($value)){
					$action = MappingService::findElement($type, $name, $value, $action);
				}
			}
		}				
		return $action;		
	}	
	
}




?>